package com.gzz.mybatis.lambda;
import java.io.Serializable;
import java.lang.invoke.SerializedLambda;
import java.lang.reflect.Method;
import java.util.function.Function;

/**
 * SqlFunction： 从lambda获取字段名和类名
 * @param <T>
 * @param <R>
 */
@FunctionalInterface
public interface SqlLambda<T, R> extends Function<T, R>, Serializable {

    default SerializedLambda getSerializedLambda(){
        try {
            Method write = this.getClass().getDeclaredMethod("writeReplace");
            write.setAccessible(true);
            return (SerializedLambda) write.invoke(this);
        } catch (Exception e) {
            throw new IllegalArgumentException();
        }
    }

    default String getImplClass() {
        return getSerializedLambda().getImplClass();
    }

    default String getImplMethodName() {
        return getSerializedLambda().getImplMethodName();
    }
}